<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
    	<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    	<link rel="icon" type="image/png" href="img/favicon.ico" sizes="16x16">
		<title>8天出行-地勤车况系统</title>
		<link rel="stylesheet" href="libs/wuui/weui.min.css" />
		<style type="text/css">
			body {
				line-height: 1.6;
				font-family: -apple-system-font, Helvetica Neue, sans-serif;
			}
			
			.page,
			body {
				background-color: #f8f8f8;
			}
			
			.sign {
				padding: 20px;
			}
			
			.logo {
				margin-top: 20px;
				margin-bottom: 3.125em;
				text-align: center;
			}
			
			.sign .weui-cell {
				border: 1px solid #e5e5e5;
				border-radius: 4px;
			}
			
			.sign .weui-btn-area {
				margin: 1.17647059em 0 0.5em;
			}
			.tips-success{
				background: #09BB07;
			}
			.tips-error{
				background: #F76260;
			}
			.toast-warn .weui-toast i.weui-icon-success-no-circle:before {
		    	content: "\EA0B";
			}
		</style>
	</head>

	<body ontouchstart>
		
		<div class="page sign js_show">
			<div class="page-bd">
				<div class="logo">
					<img src="img/logo-237x60.png" alt="">
				</div>
		
				<div class="weui-cells weui-cells_form">
					<div class="weui-cell">
						<div class="weui-cell__bd">
							<input class="weui-input" type="text" name="mobile" placeholder="请输入手机号码" />
						</div>
					</div>
				</div>
				<div class="weui-cells weui-cells_form">
					<div class="weui-cell">
						<div class="weui-cell__bd">
							<input class="weui-input" type="password" name="password" placeholder="密码" />
						</div>
					</div>
				</div>
				<div class="weui-btn-area">
					<a id="loginBtn" href="javascript:;" class="weui-btn weui-btn_primary">登&nbsp;&nbsp;录</a>
				</div>
			</div>
		</div>
		<div id="toast" style="display: none;">
		    <div class="weui_mask_transparent"></div>
		    <div class="weui_toast">
		        <i class="weui_icon_toast"></i>
		        <p class="weui_toast_content">已完成</p>
		    </div>
		</div>
		<script type="text/javascript" src="libs/jquery-2.2.3.min.js" charset="UTF-8"></script>
		<!--weui.js需要在body里面加载才起作用-->
		<script type="text/javascript" src="libs/weui.js/weui.min.js" charset="UTF-8"></script>
		<script type="text/javascript" src="js/app.js" charset="UTF-8"></script>
		<script type="text/javascript">
		$(function() {
			var login = function() {
				//window.sessionStorage.clear();
				
				var loading, mobile = $('input[name=mobile]').val(), password = $('input[name=password]').val(); 
				if("" == mobile.trim()) {
					weui.toast('请输入手机号码', {
						duration: 800,
    					className: 'toast-warn'
					});
					return ;
				}
				if("" == password.trim()) {
					weui.toast('密码不能为空', {
						duration: 800,
    					className: 'toast-warn'
					});
					return ;
				}
				
				$.ajax({
					type:"post",
					url:"/api/tukuan/car/user/login",
					data: {"mobile": mobile, "password": password},
					beforeSend: function() {
						$('#loginBtn').off('click') ;
						loading = weui.loading('验证中');
					},
					success: function(result){
						if(result.status) {
							loading.hide();
							weui.topTips(result.message, {
								duration: 2000,
								className: 'tips-success'
							});
							
							app.setJSONSessionStorage('user', result.data) ;
							
							window.location.replace('index.html') ;
						} else {
							$('#loginBtn').on('click', login);
							loading.hide();
							weui.topTips(result.message, {
								duration: 2000,
								className: 'tips-error'
							});
						}
					},
					error: function(){
						loading.hide();
						$('#loginBtn').on('click', login);
						weui.topTips('发生错误', {
							duration: 2000,
							className: 'tips-error'
						});
					}
				});
			}
			
			$('#loginBtn').on('click', login);
			
		});
		</script>
	</body>

</html>